<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>axios直接发起GET和POST请求</title>
    <link href="../image/favicon.ico" rel="shortcut icon">
</head>
<body>
    <button id="btnGet"> 发起 GET 请求 </button>
    <button id="btnPost"> 发起 POST 请求 </button>

    <script src="../lib/axios.js"></script>
    <script>
        document.getElementById('btnGet').addEventListener('click',async function (){
            const {data : res} = await axios.get('http://www.liulongbin.top:3006/api/getbooks',{
                // GET 参数
                params: { id:2 }
            })
            console.log(res.data)
        })

        document.getElementById('btnPost').addEventListener('click',async function (){
            // axios.post('url',{/* POST 请求数据 */})
            const {data : res} = await axios.post('',{
                name:'zs',
                age:18
            })
            console.log(res)
        })

    </script>
</body>
</html>